#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
void solve()
{
    string s, t;
    cin >> s >> t;
    ll l = 0, r = s.size() - 1;
    while (s[l] == t[l]&&l<s.size())
    {
        l++;
    }
    while (s[r] == t[r]&&r>=0)
    {
        r--;
    }
    auto st = s.begin();
     //cout << l << ":" << r << endl;
    // if (l!=s.size()&&r!=-1)
        reverse(s.begin() + l, s.begin() + r+1);
    //cout << s << endl;
    cout << (s == t ? "Y" : "N") << "\n";
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
